import request from '@/utils/request'
import { DictId, ObjectType } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { AxiosResponse } from 'axios'
import { Option } from '@/components/Form/types'

/*
 * 字典管理模块
 */

// 保存字典
export const saveDict = (data: any) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dict',
    method: 'post',
    data: data,
  })
}

// 获取字典列表
export const getDict = (parms: any) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dict',
    method: 'get',
    params: parms,
  })
}

// 根据字典id获取字典详情列表(分页)
export const queryDictItems = (params: any) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem/list',
    method: 'get',
    params,
  })
}

// 根据字典id获取字典详情列表(分页)
export const queryDictItemList = (dictId: string) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem',
    method: 'get',
    params: {
      dictId,
      size: 30,
    },
  })
}

export const queryDictItemByDictName = (dictName: number) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dict/queryDictItemByDictName/' + dictName,
    method: 'get',
  })
}

// 更新机构
export const updateDict = (data: ObjectType) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dict',
    method: 'put',
    data: data,
  })
}

// 保存字典详情
export const addDictItem = (data: ObjectType) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem',
    method: 'post',
    data: data,
  })
}
// 更新字典详情
export const updateDictItem = (data: ObjectType) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem',
    method: 'put',
    data: data,
  })
}

// 根据主键删除字典详情
export const deleteDictItem = (id: number) => {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem/' + id,
    method: 'delete',
  })
}

// 数据字典
export function dataDictionary(data: DictId[]): Promise<AxiosResponse<any>> {
  return request({
    url: proxy.CHECC_API_CMS + '/dictItem/codelist',
    method: 'post',
    data
  })
}
